package object3D;

import context.*;

import geometry3D.Point3D;
import geometry3D.Transform;

// Java 3D
import javax.media.j3d.Group;
import javax.media.j3d.TransformGroup;
import javax.media.j3d.Transform3D;
import javax.media.j3d.Appearance;
import com.sun.j3d.utils.geometry.Box;
import javax.vecmath.Vector3f;

// ********************************************************************
// *** CLASS: Block
// ********************************************************************
public class CenterBlock extends Block implements Context.Constants
{ //private static final boolean DEBUG=true; // Overriding Context.Constants.DEBUG
    
//  public Vector<CenterBlock> extras; // Extra object attached to this object
  
//  protected double rotateX=0; // Clockwise rotation in radians
//  protected double rotateY=0; // Clockwise rotation in radians
//  protected double rotateZ=0; // Clockwise rotation in radians
//  public void setRotate(double rx,double ry,double rz)
//  { rotateX=rx; rotateY=ry; rotateZ=rz; }
  
      
  public CenterBlock(String ident,Point3D p0,double width,double height,double depth)
  { super(ident,p0,width,height,depth);
//    this.extras=new Vector<CenterBlock>();
  }
  
  public boolean contains(Point3D p)
  { if( (p.x>=p0.x) & (p.x<=(p0.x+width)) )
    { if( (p.y>=p0.y) & (p.y<=(p0.x+height)) )
      { if( (p.z>=p0.z) & (p.z<=(p0.z+depth)) ) return(true); }
    }
    return(false);
  }
  
  // ***************************************************************************
  // *** METHOD: getModel3D
  // ***************************************************************************
  public /*abstract*/ Group getModel3D(Appearance appearance)
  { TransformGroup tg=new TransformGroup();
    Transform3D transform=new Transform3D();
    double x=p0.x;//+width/2;
    double y=p0.y;//+height/2;
    double z=p0.z;//+depth/2;
    transform.setTranslation(new Vector3f((float)x,(float)y,(float)z));
    transform=Transform.rotate(transform,rotateX,rotateY,rotateZ);
    tg.setTransform(transform);
//    Box box=new Box((float)width/2,(float)height/2,(float)depth/2,appearance);
    Box box=new Box((float)width,(float)height,(float)depth,appearance);
    tg.addChild(box);
    return(tg);
  }  
}  